home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / oa / oatalk < prev    next >
Encoding:
Text File  |  1997-08-26  |  3.0 KB  |  129 lines

  1. #!/usr/lib/scosh/utilbin/oash
  2. # (was /usr/lib/oa/utilbin/oash)
  3. # @(#) oatalk.oash 1.1 95/01/12
  4. # 95/01/12 john h. dubois iii
  5.  
  6. OALIB=${OALIB-"/usr/lib/oa"}
  7. PATH=$OALIB/utilbin:$PATH
  8.  
  9. # run ourself thru oash 
  10. oainit 2>/dev/null || exec oash -c $0 "$@"
  11.  
  12. . `findfile shell_strs`
  13.  
  14. # Usage: Clean_wmopen num lines cols top_row
  15. # Creates a window centered on column 38/39 and clears a border around it.
  16. # Uses window #30 to clear.
  17. Clean_wmopen() {
  18.     # Save vars since positional params will be changed
  19.     # N: Window number
  20.     # L: Number of lines
  21.     # C: Number of columns
  22.     # X: Top row
  23.     N=$1 L=$2 C=$3 X=$4
  24.  
  25.     set -- \
  26.     `ksh -c "echo $(($L+2)) $(($C+2)) $(($X-1)) $((38-$C/2)) $((39-$C/2))"`
  27.     newwin 30 $1 $2 $3 $4
  28.     wmclose 30
  29.     # wmopen wants window-num ysize xsize y-offset x-offset
  30.     wmopen $N $L $C $X $5
  31. }
  32.  
  33. EscWasHit() { 
  34.     oadeinit
  35.     rm -f $TEMP
  36.     exit
  37. }
  38.  
  39. # This assumes that remote finger will return lines in which the first two
  40. # lines are unneeded (system name and header) and the first word of each line
  41. # is the user name.  Unfortunately the tty column is not consistent so can't
  42. # be used.
  43. RemoteSelect() {
  44.     System=`expr $1 : '@\(.*\)'`
  45.     wmopen 3 4 43 8 19
  46.     echo "Requesting a list of logged-in users from"
  47.     echo "$System... please stand by."
  48.     wrefresh 3
  49.     finger "@$System" | tail +3 | 
  50.     awk '{j = substr($0,1,35); sub(" +$","",j); print j;}' > $TEMP
  51.     set -- `wc -l $TEMP`
  52.     set -- `expr \( $1 + 1 \) / 2 + 2`
  53.     [ "$1" -gt 23 ] && set -- 23
  54.     sleep 5
  55. #    wmclose 3
  56.     wmopen 4 $1 78 1 1
  57.     wmtitle "Select a user on $System to talk to"
  58.     wmmessage -r "$ppMessage"
  59.     pp -f $TEMP
  60.     rm -f $TEMP
  61.     [ "$PP_NUM" -eq -1 ] && EscWasHit
  62.     set -- $PP_ITEM
  63.     Talk_User="$1@$System"
  64. }
  65.  
  66. TEMP=/tmp/fm1$$
  67.  
  68. if [ $# -gt 0 ]; then
  69.     case "$1" in
  70.     @*)
  71.     RemoteSelect "$1"
  72.     rm -f $TEMP
  73.     oadeinit
  74.     [ -n "$Talk_User" ] && exec talk $Talk_User || exit 0
  75.     ;;
  76.     *)
  77.     oadeinit
  78.     echo "Usage: oatalk [@system-name]"
  79.     exit 1
  80.     ;;
  81.     esac
  82. fi
  83.  
  84. # Crude test for if we might be networked
  85. [ -c /dev/socksys ] && echo "User on another system" > $TEMP
  86. # Find writable users
  87. who -T | awk '$2 == "+" {
  88.     printf "%-8s %-7s %s %s %s\n",$1,$3,$4,$5,$6
  89. }' >> $TEMP
  90.  
  91. if [ ! -s $TEMP ]; then
  92.     rm -f $TEMP
  93.     oadeinit
  94.     echo -n "No writable users are logged on.  Press return to continue... "
  95.     read response
  96.     exit
  97. fi
  98.  
  99. ppMessage="Press return to select or escape to quit" 
  100.  
  101. set -- `wc -l $TEMP`
  102. set -- `expr \( $1 + 1 \) / 2 + 2`
  103. wmopen 1 $1 67 1 6
  104. wmtitle "Select a user to talk to" 
  105. wmmessage -r "$ppMessage" 
  106. pp -f $TEMP
  107. rm -f $TEMP
  108. [ "$PP_NUM" -eq -1 ] && EscWasHit
  109. set -- $PP_ITEM
  110. Talk_User="$1 $2"
  111. if [ "$1" = User ]; then
  112.     Clean_wmopen 2 5 61 5
  113.     wmtitle "Remote User Selection"
  114.     echo "Enter username@host.name for the user you wish to talk to,"
  115.     echo "or @host.name to get a list of users on the remote host."
  116.     wmmessage -r "Press return when done"
  117.     echo -n "-> "
  118.     wrefresh 2
  119.     read Talk_User
  120.     case "$Talk_User" in
  121.     @*)
  122.     RemoteSelect "$Talk_User";;
  123.     esac
  124. fi
  125.  
  126. rm -f $TEMP
  127. oadeinit
  128. [ -n "$Talk_User" ] && exec talk $Talk_User
  129.